<template>
  <div class="container">
    <keep-alive>
      <router-view class="content"></router-view>
    </keep-alive>
    <div class="tabbar">
      <div class="tabbar-item" @click="onTabbarHomeClick">
        <i class="iconfont" :class="{'tabbar-item-active': currentIndex === 0}">&#xe600;</i>
        <span :class="{'tabbar-item-active': currentIndex === 0}">首页</span>
      </div>
      <div class="tabbar-item" @click="onTabbarShopCarClick">
        <i class="iconfont" :class="{'tabbar-item-active': currentIndex === 1}">&#xe899;</i>
        <span :class="{'tabbar-item-active': currentIndex === 1}">购物车</span>
      </div>
      <div class="tabbar-item" @click="onTabbarOrderClick">
        <i class="iconfont" :class="{'tabbar-item-active': currentIndex === 2}">&#xe713;</i>
        <span :class="{'tabbar-item-active': currentIndex === 2}">订单</span>
      </div>
      <div class="tabbar-item" @click="onTabbarMineClick">
        <i class="iconfont" :class="{'tabbar-item-active': currentIndex === 3}">&#xe601;</i>
        <span :class="{'tabbar-item-active': currentIndex === 3}">我的</span>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data () {
    return {
      currentIndex: 0
    }
  },
  created () {
    const routeName = this.$route.name.toLocaleLowerCase()
    switch (routeName) {
      case 'home':
        this.currentIndex = 0
        break
      case 'shopcar':
        this.currentIndex = 1
        break
      case 'order':
        this.currentIndex = 2
        break
      case 'mine':
        this.currentIndex = 3
        break
      default:
        this.currentIndex = 0
    }
  },
  methods: {
    onTabbarHomeClick (e) {
      this.currentIndex = 0
      this.$router.push('/')
    },
    onTabbarShopCarClick () {
      this.currentIndex = 1
      this.$router.push('/shopCar')
    },
    onTabbarOrderClick () {
      this.currentIndex = 2
      this.$router.push('/order')
    },
    onTabbarMineClick () {
      this.currentIndex = 3
      this.$router.push('/mine')
    }
  }
}
</script>
<style scoped lang = 'scss'>
.container {
  height: 100vh;
  .content {
    height: calc(100vh - 49px);
    overflow: hidden;
  }
  .tabbar {
    height: 49px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0px 29px;
    box-sizing: border-box;
    flex-shrink: 0;
    font-weight: bold;
    &-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      i {
        font-size: 18px;
      }
      span {
        margin-top: 2px;
        font-size: 12px;
      }
      &-active {
        color: #1fa4fc;
        transform: scale(1.2);
        transition: all 0.2s linear 0s;
        margin-bottom: 2px;
        font-weight: bold;
      }
    }
  }
}
</style>
